var columns = [{
    checkbox: true
},
{
    field: "id",
    title: "编号"
},
{
    field: "uuid",
    title: "记录UUID",
    visible: false
},
{
    field: "table",
    title: "待检表名"
},
{
    field: "field",
    title: "待检字段名"
},
{
    field: "referenceTable",
    title: "参考表名"
},
{
    field: "referenceField",
    title: "参考字段名"
},
{
    field: "deleteMoment",
    title: "删除时",
    formatter: function(value, row, index) {
        switch (value) {
            case 1:
                return "RESTRICT";
            case 2:
                return "NO ACTION";
            case 3:
                return "CASCADE";
            case 4:
                return "SET NULL";
        }
    }
},
{
    field: "updateMoment",
    title: "更新时",
    formatter: function(value, row, index) {
        switch (value) {
            case 1:
                return "RESTRICT";
            case 2:
                return "NO ACTION";
            case 3:
                return "CASCADE";
            case 4:
                return "SET NULL";
        }
    }
},
{
    field: "creatorId",
    title: "创建者ID",
    visible: false
},
{
    field: "creatorUuid",
    title: "创建者UUID",
    visible: false
},
{
    field: "createTime",
    title: "创建时间",
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd");
    }
},
{
    field: "updatorId",
    title: "修改者ID",
    visible: false
},
{
    field: "updatorUuid",
    title: "修改者UUID",
    visible: false
},
{
    field: "updateTime",
    title: "更新时间",
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd hh:mm:ss");
    },
    visible: false
}];


function queryParams(params) {
    var param = {
        pageNumber: params.pageNumber,
        pageSize: params.pageSize,
        keyword: $('.search input').val()
    };
    return param;
}

// 通过table id获取需要初始化的table
var foreignkey_table = $('#foreignkey_table'); 

// 初始化的table
initTable(foreignkey_table, $('#foreignkey_toolbar'), 'foreignKey/load', columns, queryParams, 'zh-CN', true);

// 给搜索框添加提示
$('.search input').attr("placeholder", "搜索待检表名的");


// 删除按钮事件
function btnDel(){

    var ids = getSelections(foreignkey_table, 'id');
    
    if (ids.length > 0) {
        // 弹出框-开始
        layer.confirm('删除选中信息可能会造成严重的后果，确定要删除吗？', {
            icon: 3,
            title: '警告'
        },
        function(index, elem) {
            $.ajax({
                url: "foreignKey/delete",
                traditional: true,
                data: {
                    "ids": ids
                },
                type: "POST",
                success: function(result) {
                    if (result['status'] == 0){
                        layer.msg(result['message'], {
                            icon: 1,
                            time: 2000
                        });
                        refreshDelTable(foreignkey_table, ids.length);
                    } else {
                        layer.msg(result['message'], {
                            icon: 2,
                            time: 2000
                        });
                    }
                }
            });
            layer.close(index);
        });
        // 弹出框-结束
        
    } else {
        layer.msg("你没有选择数据", {
            icon: 0
        });
    }
}